<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/DataSet">
    CREATE PROCEDURE CORE_<xsl:value-of select="Table/TABLE_NAME"/>_GetBy<xsl:for-each select="Table"><xsl:if test="starts-with(CONSTRAINT_NAME,'PK')"><xsl:value-of select="COLUMN_NAME"/></xsl:if></xsl:for-each><xsl:text> </xsl:text>@<xsl:for-each select="Table"><xsl:if test="starts-with(CONSTRAINT_NAME,'PK')"><xsl:value-of select="COLUMN_NAME"/><xsl:text> </xsl:text> <xsl:value-of select="DATA_TYPE"/></xsl:if></xsl:for-each>
    AS
    BEGIN
      SELECT
        <xsl:for-each select="Table">
        <xsl:value-of select="COLUMN_NAME"/><xsl:if test="position() != last()">,</xsl:if><xsl:text>
        </xsl:text>
      </xsl:for-each>
      FROM <xsl:value-of select="Table/TABLE_NAME"/>
      WHERE <xsl:for-each select="Table"><xsl:if test="starts-with(CONSTRAINT_NAME,'PK')">[<xsl:value-of select="COLUMN_NAME"/>] = @<xsl:value-of select="COLUMN_NAME"/></xsl:if>
    </xsl:for-each>
    END
    GO
  </xsl:template>
</xsl:stylesheet>